home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v10n11.arc / DELAY.BAS < prev    next >
BASIC Source File  |  1991-05-10  |  1KB  |  40 lines

  1.  
  2. DECLARE FUNCTION CalcDelay& ()
  3. DECLARE SUB DoDelay (MSecs%, Factor&)
  4.  
  5. Factor& = CalcDelay&
  6. INPUT "Enter a delay period in milliseconds: ", MSecs%
  7. PRINT "Stand by ..."
  8. CALL DoDelay(MSecs%, Factor&)
  9. PRINT "Done!"
  10.  
  11. FUNCTION CalcDelay& STATIC
  12.  
  13.     Fudge& = 0                       'clear the "fudge factor" accumulator
  14.     DEF SEG = 0                      'look at the timer bytes in low memory
  15.  
  16.     Start% = PEEK(&H46C)             'look at the current low-byte count
  17.     DO                               'wait until that byte just changes
  18.     LOOP WHILE PEEK(&H46C) = Start%  '  (up to 1/18th second)
  19.     Start% = PEEK(&H46C)             'get the new low-byte count again
  20.  
  21.     DO                               'now we're synced up with the start of
  22.        Fudge& = Fudge& + 1           '  a new, full 1/18th second period
  23.     LOOP WHILE PEEK(&H46C) = Start%  'accumulate the count for 1/18th second
  24.  
  25.     CalcDelay& = Fudge&              'assign the function output
  26.     DEF SEG                          'restore BASIC's original segment
  27.  
  28. END FUNCTION
  29.  
  30. SUB DoDelay (MSecs%, Factor&)
  31.  
  32.     FOR X% = 1 TO MSecs%
  33.         LoopTime& = Factor& \ 40
  34.         DO
  35.            LoopTime& = LoopTime& - 1
  36.         LOOP WHILE LoopTime&
  37.     NEXT
  38.  
  39. END SUB
  40.